/*
 * paymentBO.java
 *
 * Created on March 17, 2007, 2:14 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.mystuff;

import java.util.*;
import java.util.Date;

/**
 *
 * @author Sandi Griffiths
 */
public class transBO {
    
    private String transacid;
    private String payid;
    private String storeid;
    private String empid;
    private String custid;
    private String date;
    private ArrayList<tlineBO> tllist = null;
    private paymentBO pay = null;
    private double subtotal;
    private double tax;
    private double total;
    private boolean complete = false;
    private boolean dirty = false;   
    private boolean alreadyInDatabase = false;
    
    /** Creates a new instance of customerBO */
    public transBO() {
    }
        
    public transBO(String transacid) {
    this.transacid = transacid;
    Date x = new Date();
    date = x.toString();
    }
    
    public String getTransactionId() {
        return transacid;
    }

    public String getPaymentId() {
        return payid;
    }

    public void setPaymentId(String payid) {
        this.payid = payid;
        setDirty(true);
    }

    public String getStoreId() {
        return storeid;
    }

    public void setStoreId(String storeid) {
        this.storeid = storeid;
        setDirty(true);
    }
    
    public String getEmpId(){
        return empid;
    }

    public void setEmployeeId(String empid){
        this.empid = empid;
        setDirty(true);
    }
    
    public String getCustId(){
        return custid;
    }
    
    public void setCustId(String custid){
        this.custid = custid;
        setDirty(true);
    }
    
    public boolean getComplete(){
        return complete;
    }
    
    public void setComplete(boolean complete){
        this.complete = complete;
        setDirty(true);
    }
    
    public paymentBO getPayment(){
        return pay;
    }
    
    public void setPayment(paymentBO pay){
        this.pay = pay;
        this.setPaymentId(pay.getPaymentId());
    }
    
    public String getDate(){
        return date;
    }
    
    public void setDate(String date){
        this.date = date;
        setDirty(true);
    }
    
    public ArrayList getTransLineList(){
        return tllist;
    }
   
    public void clearlist(){
        tllist.clear();
    }
    
    public void add(tlineBO tl){
        if(tllist ==null)
            tllist = new ArrayList();
        tllist.add(tl);
    }
    
    public void setTransLineList(ArrayList<tlineBO> tllist){
        this.tllist = tllist;
    }
    
    public double getTotal(){
        return total;
    }
    
    public void setTotal(double total){
        this.total = total;
    }
    
    public void calculatePrice(){
        if(tllist!=null){
            subtotal = 0;
            for(int x=0; x<tllist.size(); x++){
                subtotal+= tllist.get(x).getPrice();
            }
            tax = subtotal * .07;
            total = subtotal + tax;
        }
        setDirty(true);
    }
    
    public String toString(){
        return "Transac id : "+ this.getTransactionId()+" \n"+
               "Payment id : "+ this.getPaymentId()+" \n"+
               "Store   id : "+ this.getStoreId() +" \n"+
               "Employeeid : "+ this.getEmpId()+ "\n" +
               "Customerid : "+ this.getClass()+ "\n"+
               "Completed  : "+ this.getComplete() + "\n"+
               "Date       : "+ this.getDate() + "\n"+
               "Price      : "+ this.getTotal()+ "\n";
    }

    public boolean isDirty() {
        return dirty;
    }

    public void setDirty(boolean dirty) {
        this.dirty = dirty;
    }

    public boolean isAlreadyInDatabase() {
        return alreadyInDatabase;
    }

    public void setAlreadyInDatabase(boolean alreadyInDatabase) {
        this.alreadyInDatabase = alreadyInDatabase;
    }
}